#include"login.h"
#include "managerswin.h"
#include "staffwin.h"
#include "userswin.h"
#include <QApplication>
#include <QObject>
#include <QMainWindow>

extern "C" {
#include "database.h"
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    open_database();
    initialize_all_tables();
    Login* w = new Login();
    w->show();

    QObject::connect(w, &Login::loginSuccess, [&](int& userType, const QString& userName){

        if (userType == 1) {
            managerswin* mainWindow = new managerswin();
            mainWindow->setManagerInfo(userName);
            mainWindow->setAttribute(Qt::WA_DeleteOnClose);
            mainWindow->show();
        } else if (userType == 2) {
            staffwin* mainWindow = new staffwin();
            mainWindow->setStaffInfo(userName);
            mainWindow->setAttribute(Qt::WA_DeleteOnClose);
            mainWindow->show();
        } else if (userType == 3) {
            userswin* mainWindow = new userswin();
            mainWindow->setUserInfo(userName);
            mainWindow->setAttribute(Qt::WA_DeleteOnClose);
            mainWindow->show();
        }

            w->deleteLater();
    });

    int main_result = a.exec();
    close_database();
    return main_result;

}
